package com.vehicle.service.Impl;

import cn.hutool.core.collection.CollectionUtil;
import com.vehicle.domains.entity.SysRolePermissionEntity;
import com.vehicle.mapper.SysRolePermissionMapper;
import com.vehicle.service.SysRolePermissionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysRolePermissionServiceImpl implements SysRolePermissionService {

    @Resource
    private SysRolePermissionMapper sysRolePermissionMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRolePermissions(Long roleId, List<SysRolePermissionEntity> list) {
        sysRolePermissionMapper.deletePermissionsByRoleId(roleId);
        if (CollectionUtil.isNotEmpty(list)) {
            sysRolePermissionMapper.batchInsertRolePermissions(list);
        }
    }
}
